package org.millioncall.yueyoga.admin.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.millioncall.openplatform.util.StringUtils;
import org.millioncall.yueyoga.admin.model.Clazz;
import org.millioncall.yueyoga.admin.model.Group;
import org.millioncall.yueyoga.admin.model.Member;
import org.millioncall.yueyoga.admin.service.ClazzService;
import org.millioncall.yueyoga.admin.service.MemberService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ClazzAllAction extends BaseAction {
	private ClazzService clazzService;
	private MemberService memberService;

	public MemberService getMemberService() {
		return memberService;
	}

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}

	public ClazzService getClazzService() {
		return clazzService;
	}

	public void setClazzService(ClazzService clazzService) {
		this.clazzService = clazzService;
	}

	/** 查询班级基本信息 **/
	@RequestMapping(value = "/findAllClass.jhtml")
	public String toUpdateClazz(HttpServletRequest request,
			HttpServletResponse response, ModelMap model) {

		super.initFrontHeader(request, model);

		String strId = request.getParameter("classId");
		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Object> map1 = new HashMap<String, Object>();
		int Id = 0;
		if (!StringUtils.isBlank(strId)) {
			Id = Integer.parseInt(strId);
		}
		
		List<Integer> groupIds = new ArrayList<Integer>();
		for (Group group : this.getUser(request).getGroups()) {
			groupIds.add(group.getId());
		}
		map1.put("id", Id);
		map1.put("groups", groupIds);
		map1.put("hallcode", this.getUser(request).getOrganizationId());
		Clazz clazz = clazzService.findById(map1);// 根据ID查询班级
		/** 查询所有的用户不安分页查询,用来显示头像 **/		
		List<Member> memberAll = memberService.getMemberAll(map);
		model.put("memberAll", memberAll);
		model.put("name", clazz.getName());
		model.put("state", clazz.getState());
		model.put("assignedTo", clazz.getAssignedTo().getUserDetail().getName());
		model.put("startDate", clazz.getStartDate());
		model.put("endDate", clazz.getEndDate());
		model.put("startWeek", clazz.getStartWeek());
		model.put("endWeek", clazz.getEndWeek());
		model.put("remarks", clazz.getReamarks());
		if (clazz.getProduct() != null)
			model.put("productId", clazz.getProduct().getProductId());
		else
			model.put("productId", "0");
		model.put("cheduleList", clazz.getChedules());
		model.put("classId", strId);

		return "class_all";
	}

}
